/*
 * Filename:    WarnResultDetailServiceImpl.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年11月12日
 */
package com.paic.mhis.hcpms.warning.biz.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.paic.mhis.hcpms.warning.biz.service.WarnResultDetailService;
import com.paic.mhis.hcpms.warning.dao.WarnResultDetailDAO;
import com.paic.mhis.hcpms.warning.dto.WarnResultDetailDTO;

@Service("warnResultDetailService")
public class WarnResultDetailServiceImpl implements WarnResultDetailService {
	@Autowired
	private WarnResultDetailDAO warnResultDetailDAO;

	@Override
	public int addWarnResultDetail(JSONObject transferJson, Map<String, Object> paramMap) {
		JSONArray jsonArr = (JSONArray) transferJson.remove("warnResultDetails");
		List<WarnResultDetailDTO> list = new ArrayList<WarnResultDetailDTO>();
		if (jsonArr.size() > 0) {
			for (int j = 0; j < jsonArr.size(); j++) {
				WarnResultDetailDTO dto = new WarnResultDetailDTO();
				JSONObject tempJson = jsonArr.getJSONObject(j);
				dto = JSONObject.toJavaObject(tempJson, WarnResultDetailDTO.class);
				list.add(dto);
			}
			warnResultDetailDAO.addWarnResultDetail(list);
			return 1;
		}
		return 0;
	}

	@Override
	public List<WarnResultDetailDTO> warningResultQueryDetail(String warnNo) {
		if (StringUtils.isEmpty(warnNo)) {
			return null;
		}
		return warnResultDetailDAO.warningResultQueryDetail(warnNo);
	}

}
